namespace CIS.Customer
{
    using CISLib;
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class CustomerInfoHealthCostumePage : Page
    {
        protected TextBox AllergyTxb;
        protected TextBox BrandPreTxb;
        protected DropDownList EyesightDdl;
        protected DropDownList HealthDdl;
        protected TextBox HipMeasurementTxb;
        protected Image iBtnCustomer;
        protected ImageButton iBtnGray3;
        protected ImageButton iBtnOrange0;
        protected ImageButton iBtnOrange1;
        protected ImageButton iBtnOrange2;
        protected ImageButton iBtnOrange4;
        protected ImageButton iBtnOrange5;
        protected ImageButton iBtnOrange6;
        protected ImageButton iBtnOrange7;
        protected ImageButton iBtnOrange8;
        protected Label lbAllergy;
        protected Label lbBrandPre;
        protected Label lbClothingSituation;
        protected Label lbEyesight;
        protected Label lbHealth;
        protected Label lbHealthSituation;
        protected Label lbHip;
        protected Label lbInch1;
        protected Label lbInch2;
        protected Label lbInch3;
        protected Label lbMajorOperation;
        protected Label lbNeck;
        protected Label lbSaveMsg;
        protected Label lbShoes;
        protected Label lbSpecialDisease;
        protected TextBox MajorOperationTxb;
        protected TextBox NeckMeasurementTxb;
        protected UserPrincipal Principal = null;
        protected Button saveBtn;
        protected TextBox ShoesSizeTxb;
        protected TextBox SpecialDiseaseTxb;

        private void FillPageForCostume()
        {
            if (ManageCustomer.IsExistSameCoustomerCostumeInfo(new Guid(base.Request.QueryString["CustomerId"])))
            {
                try
                {
                    CustomerCostumeInfo customerCostumeInfo = new CustomerCostumeInfo();
                    customerCostumeInfo = ManageCustomer.GetCustomerCostumeInfoViaId(new Guid(base.Request.QueryString["CustomerId"].ToString()));
                    this.NeckMeasurementTxb.Text = customerCostumeInfo.NeckMeasurement;
                    this.ShoesSizeTxb.Text = customerCostumeInfo.ShoesSize;
                    this.HipMeasurementTxb.Text = customerCostumeInfo.HipMeasurement;
                    this.BrandPreTxb.Text = customerCostumeInfo.BrandPre;
                }
                catch (Exception)
                {
                }
            }
        }

        private void FillPageForHealth()
        {
            if (ManageCustomer.IsExistSameCoustomerHealthInfo(new Guid(base.Request.QueryString["CustomerId"])))
            {
                try
                {
                    CustomerHealth customerHealth = new CustomerHealth();
                    customerHealth = ManageCustomer.GetCustomerHealthViaId(new Guid(base.Request.QueryString["CustomerId"].ToString()));
                    this.MajorOperationTxb.Text = customerHealth.MajorOperation;
                    this.SpecialDiseaseTxb.Text = customerHealth.SpecialDisease;
                    this.AllergyTxb.Text = customerHealth.Allergy;
                    for (int i = 0; i < this.HealthDdl.Items.Count; i++)
                    {
                        if (this.HealthDdl.Items[i].Value == customerHealth.HealthStatus.ToString())
                        {
                            this.HealthDdl.SelectedIndex = i;
                            break;
                        }
                    }
                    for (int i = 0; i < this.EyesightDdl.Items.Count; i++)
                    {
                        if (this.EyesightDdl.Items[i].Value == customerHealth.Eyesight.ToString())
                        {
                            this.EyesightDdl.SelectedIndex = i;
                            return;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }

        private void iBtnOrange0_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerBasicInfoPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange1_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoPersonalPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange2_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoPreferencePage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange4_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoTravelPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange5_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoStudyPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange6_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoWorkPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange7_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoFamilyPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange8_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoOtherPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void InitializeComponent()
        {
            this.iBtnOrange0.Click += new ImageClickEventHandler(this.iBtnOrange0_Click);
            this.iBtnOrange1.Click += new ImageClickEventHandler(this.iBtnOrange1_Click);
            this.iBtnOrange2.Click += new ImageClickEventHandler(this.iBtnOrange2_Click);
            this.iBtnOrange4.Click += new ImageClickEventHandler(this.iBtnOrange4_Click);
            this.iBtnOrange5.Click += new ImageClickEventHandler(this.iBtnOrange5_Click);
            this.iBtnOrange6.Click += new ImageClickEventHandler(this.iBtnOrange6_Click);
            this.iBtnOrange7.Click += new ImageClickEventHandler(this.iBtnOrange7_Click);
            this.iBtnOrange8.Click += new ImageClickEventHandler(this.iBtnOrange8_Click);
            this.saveBtn.Click += new EventHandler(this.saveBtn_Click);
            base.Load += new EventHandler(this.Page_Load);
        }

        private void InitPage()
        {
            this.SetFromImage();
            this.SetFrom();
            string language = this.Session["language"].ToString();
            if (language == "cn")
            {
                this.HealthDdl.Items.Clear();
                ListItem healthItem0 = new ListItem();
                healthItem0.Text = " ";
                healthItem0.Value = "3";
                ListItem healthItem1 = new ListItem();
                healthItem1.Text = "良好";
                healthItem1.Value = "0";
                ListItem healthItem2 = new ListItem();
                healthItem2.Text = "一般";
                healthItem2.Value = "1";
                ListItem healthItem3 = new ListItem();
                healthItem3.Text = "较差";
                healthItem3.Value = "2";
                this.HealthDdl.Items.Add(healthItem0);
                this.HealthDdl.Items.Add(healthItem1);
                this.HealthDdl.Items.Add(healthItem2);
                this.HealthDdl.Items.Add(healthItem3);
            }
            else if (language == "en")
            {
                this.HealthDdl.Items.Clear();
                ListItem healthItem0 = new ListItem();
                healthItem0.Text = " ";
                healthItem0.Value = "3";
                ListItem healthItem1 = new ListItem();
                healthItem1.Text = "Good";
                healthItem1.Value = "0";
                ListItem healthItem2 = new ListItem();
                healthItem2.Text = "Commonly";
                healthItem2.Value = "1";
                ListItem healthItem3 = new ListItem();
                healthItem3.Text = "Bad";
                healthItem3.Value = "2";
                this.HealthDdl.Items.Add(healthItem0);
                this.HealthDdl.Items.Add(healthItem1);
                this.HealthDdl.Items.Add(healthItem2);
                this.HealthDdl.Items.Add(healthItem3);
            }
            if (language == "cn")
            {
                this.EyesightDdl.Items.Clear();
                ListItem EyesightItem0 = new ListItem();
                EyesightItem0.Text = " ";
                EyesightItem0.Value = "3";
                ListItem EyesightItem1 = new ListItem();
                EyesightItem1.Text = "良好";
                EyesightItem1.Value = "0";
                ListItem EyesightItem2 = new ListItem();
                EyesightItem2.Text = "一般";
                EyesightItem2.Value = "1";
                ListItem EyesightItem3 = new ListItem();
                EyesightItem3.Text = "较差";
                EyesightItem3.Value = "2";
                this.EyesightDdl.Items.Add(EyesightItem0);
                this.EyesightDdl.Items.Add(EyesightItem1);
                this.EyesightDdl.Items.Add(EyesightItem2);
                this.EyesightDdl.Items.Add(EyesightItem3);
            }
            else if (language == "en")
            {
                this.EyesightDdl.Items.Clear();
                ListItem EyesightItem0 = new ListItem();
                EyesightItem0.Text = " ";
                EyesightItem0.Value = "3";
                ListItem EyesightItem1 = new ListItem();
                EyesightItem1.Text = "Good";
                EyesightItem1.Value = "0";
                ListItem EyesightItem2 = new ListItem();
                EyesightItem2.Text = "Commonly";
                EyesightItem2.Value = "1";
                ListItem EyesightItem3 = new ListItem();
                EyesightItem3.Text = "Bad";
                EyesightItem3.Value = "2";
                this.EyesightDdl.Items.Add(EyesightItem0);
                this.EyesightDdl.Items.Add(EyesightItem1);
                this.EyesightDdl.Items.Add(EyesightItem2);
                this.EyesightDdl.Items.Add(EyesightItem3);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
            this.Principal = this.Context.User as UserPrincipal;
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.SelectAuth();
            }
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            string strMajorOperation = this.MajorOperationTxb.Text.Trim();
            string strSpecialDisease = this.SpecialDiseaseTxb.Text.Trim();
            string strAllergy = this.AllergyTxb.Text.Trim();
            int iHealth = Convert.ToInt32(this.HealthDdl.SelectedItem.Value);
            int iEyesight = Convert.ToInt32(this.EyesightDdl.SelectedItem.Value);
            string strNeckMeasurement = this.NeckMeasurementTxb.Text.Trim();
            string strShoesSize = this.ShoesSizeTxb.Text.Trim();
            string strHipMeasurement = this.HipMeasurementTxb.Text.Trim();
            string strBrandPre = this.BrandPreTxb.Text.Trim();
            try
            {
                if (ManageCustomer.IsExistSameCoustomerHealthInfo(new Guid(base.Request.QueryString["CustomerId"])))
                {
                    ManageCustomer.UpdateCustomerHealthInfo(new Guid(base.Request.QueryString["CustomerId"]), iHealth, iEyesight, strMajorOperation, strSpecialDisease, strAllergy);
                }
                else
                {
                    ManageCustomer.InsertNewCustomerHealthInfo(new Guid(base.Request.QueryString["CustomerId"]), iHealth, iEyesight, strMajorOperation, strSpecialDisease, strAllergy);
                }
            }
            catch (Exception ex)
            {
                this.lbSaveMsg.Text = ex.Message;
                return;
            }
            try
            {
                if (ManageCustomer.IsExistSameCoustomerCostumeInfo(new Guid(base.Request.QueryString["CustomerId"])))
                {
                    ManageCustomer.UpdateCustomerCostumeInfo(new Guid(base.Request.QueryString["CustomerId"]), strNeckMeasurement, strShoesSize, strHipMeasurement, strBrandPre);
                    ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "UpdateCostume", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, ManageCustomer.GetCustomerBasicInfoViaId(new Guid(base.Request.QueryString["CustomerId"])).Name, new Guid(base.Request.QueryString["CustomerId"]));
                }
                else
                {
                    ManageCustomer.InsertNewCustomerCostumeInfo(new Guid(base.Request.QueryString["CustomerId"]), strNeckMeasurement, strShoesSize, strHipMeasurement, strBrandPre);
                    ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "InsertCostume", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, ManageCustomer.GetCustomerBasicInfoViaId(new Guid(base.Request.QueryString["CustomerId"])).Name);
                }
            }
            catch (Exception ex)
            {
                this.lbSaveMsg.Text = ex.Message;
                return;
            }
            this.lbSaveMsg.Text = "Save successfully!";
        }

        private void SelectAuth()
        {
            if (this.Principal.OwnRole.TypeB == 0)
            {
                this.InitPage();
                this.FillPageForHealth();
                this.FillPageForCostume();
                this.MajorOperationTxb.ReadOnly = true;
                this.SpecialDiseaseTxb.ReadOnly = true;
                this.AllergyTxb.ReadOnly = true;
                this.NeckMeasurementTxb.ReadOnly = true;
                this.ShoesSizeTxb.ReadOnly = true;
                this.HipMeasurementTxb.ReadOnly = true;
                this.BrandPreTxb.ReadOnly = true;
                this.saveBtn.Visible = false;
            }
            else if (this.Principal.OwnRole.TypeB == 1)
            {
                this.InitPage();
                this.FillPageForHealth();
                this.FillPageForCostume();
            }
            Guid customerId = new Guid(base.Request.QueryString["CustomerId"]);
            if ((this.Principal.SysUser.IsAdmin <= 0) && !ManageSystemConfig.IsThisCustomerMaster(this.Principal.SysUser.UserId, customerId))
            {
                this.MajorOperationTxb.ReadOnly = true;
                this.SpecialDiseaseTxb.ReadOnly = true;
                this.AllergyTxb.ReadOnly = true;
                this.NeckMeasurementTxb.ReadOnly = true;
                this.ShoesSizeTxb.ReadOnly = true;
                this.HipMeasurementTxb.ReadOnly = true;
                this.BrandPreTxb.ReadOnly = true;
                this.saveBtn.Visible = false;
            }
        }

        private void SetFrom()
        {
            string language = this.Session["language"].ToString();
            string path = base.Server.MapPath("~/CIS/LanguageConfig.xml");
            this.lbHealthSituation.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbHealthSituation", language, path);
            this.lbHealth.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbHealth", language, path);
            this.lbEyesight.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbEyesight", language, path);
            this.lbMajorOperation.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbMajorOperation", language, path);
            this.lbSpecialDisease.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbSpecialDisease", language, path);
            this.lbAllergy.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbAllergy", language, path);
            this.lbClothingSituation.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbClothingSituation", language, path);
            this.lbNeck.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbNeck", language, path);
            this.lbShoes.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbShoes", language, path);
            this.lbHip.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbHip", language, path);
            this.lbBrandPre.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbBrandPre", language, path);
            this.saveBtn.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "saveBtn", language, path);
            this.lbInch1.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbInch1", language, path);
            this.lbInch2.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbInch2", language, path);
            this.lbInch3.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerInfoHealthCostumePage", "lbInch3", language, path);
        }

        private void SetFromImage()
        {
            switch (this.Session["language"].ToString())
            {
                case "cn":
                    this.iBtnCustomer.ImageUrl = "../images/title_customerinfo.jpg";
                    this.iBtnOrange0.ImageUrl = "../images/title_CustomerInfo_lable_1_orange.jpg";
                    this.iBtnOrange1.ImageUrl = "../images/title_CustomerInfo_lable_2_orange.jpg";
                    this.iBtnOrange2.ImageUrl = "../images/title_CustomerInfo_lable_3_orange.jpg";
                    this.iBtnGray3.ImageUrl = "../images/title_CustomerInfo_lable_4_Gray.jpg";
                    this.iBtnOrange4.ImageUrl = "../images/title_CustomerInfo_lable_5_orange.jpg";
                    this.iBtnOrange5.ImageUrl = "../images/title_CustomerInfo_lable_6_orange.jpg";
                    this.iBtnOrange6.ImageUrl = "../images/title_CustomerInfo_lable_7_orange.jpg";
                    this.iBtnOrange7.ImageUrl = "../images/title_CustomerInfo_lable_8_orange.jpg";
                    this.iBtnOrange8.ImageUrl = "../images/title_CustomerInfo_lable_9_orange.gif";
                    break;

                case "en":
                    this.iBtnCustomer.ImageUrl = "../images/title_customerinfoEn.jpg";
                    this.iBtnOrange0.ImageUrl = "../images/title_CustomerInfoEn_lable_1_orange.jpg";
                    this.iBtnOrange1.ImageUrl = "../images/title_CustomerInfoEn_lable_2_orange.jpg";
                    this.iBtnOrange2.ImageUrl = "../images/title_CustomerInfoEn_lable_3_orange.jpg";
                    this.iBtnGray3.ImageUrl = "../images/title_CustomerInfoEn_lable_4_Gray.jpg";
                    this.iBtnOrange4.ImageUrl = "../images/title_CustomerInfoEn_lable_5_orange.jpg";
                    this.iBtnOrange5.ImageUrl = "../images/title_CustomerInfoEn_lable_6_orange.jpg";
                    this.iBtnOrange6.ImageUrl = "../images/title_CustomerInfoEn_lable_7_orange.jpg";
                    this.iBtnOrange7.ImageUrl = "../images/title_CustomerInfoEn_lable_8_orange.jpg";
                    this.iBtnOrange8.ImageUrl = "../images/title_CustomerInfoEn_lable_9_orange.gif";
                    break;
            }
        }
    }
}

